#include "Spring.h"
#include "ADUGameManager.h"

#define PM_RATIO 32.0

Spring::Spring() {
	mSpeed = 0;
/*
	b2BodyDef _boxBodyDef;
	_boxBodyDef.userData = NULL;
	_boxBodyDef.type = b2_staticBody;
	_boxBodyDef.position.Set(300 / PTM_RATIO, 300 / PTM_RATIO);
	mBody = GameManager::getInstance()->mWorld->CreateBody(&_boxBodyDef);

	b2EdgeShape shape;
	shape.m_radius = 5.0f / PTM_RATIO;

	b2FixtureDef boxShapedef;
	boxShapedef.shape = &shape;
	boxShapedef.density = 0.8f;
	boxShapedef.restitution = 0.2f;
	boxShapedef.friction = 0.9f;

	b2Fixture* boxFixture;
	boxFixture = mBody->CreateFixture(&boxShapedef);
*/
}

Spring::~Spring() {

}

void Spring::SetSpeed(float _speed) {
	mSpeed = _speed;
}

void Spring::SetOriginPos(Vec2 _pos) {
	mX = _pos.x;
	mY = _pos.y;
	mOrinY = mY;
	mYSurface = mOrinY;
	//LoadBodyPos();
}

void Spring::SetId(int _id) {
	mId = _id;
}

void Spring::LoadBodyPos() {
//	mBody->SetTransform(mX / PTM_RATIO, mY / PTM_RATIO, mBody->GetAngle());
}

Vec2 Spring::GetPos() {
	return Vec2(mX, mY);
}

void Spring::OnUpdate(float dt) {
	float delta = mYSurface - mY;
	float delta2;
	delta2 = mTension * delta - mSpeed * mDamping;
	mSpeed += delta2;
	mY += mSpeed;
	//LoadBodyPos();
}
